import { Config } from "../config"
import { DB } from "../db"

let tableName = "t_config_gamename"
let redis = DB.redis
async function getGameName(h:string,areaID:string) {
	let gameName = await redis.hget(tableName,areaID)
	return gameName
}

async function getAreaID(h:string,gameName:string) {
	let areaID = await redis.hget(tableName,gameName)
	return areaID
}

export let RpcGameNameConfig = {
	gameName:getGameName,
	areaID:getAreaID,
}

async function initConfig() {
	let localConfig = Config.localConfig
	if(localConfig.gameNames) {
		await redis.del(tableName)
		for(let info of localConfig.gameNames) {
			await redis.hset(tableName,info.areaID,info.gameName)
			await redis.hset(tableName,info.gameName,info.areaID)
		}
	}
}

initConfig()